package com.zhuangyuan.cloud.data.repository.sqlite;

import com.zhuangyuan.cloud.data.entities.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CategoryRepository extends JpaRepository<Category,String> {
    List<Category> findByName(String name);
    @Query("select c from Category c where parentId = :id")
    List<Category> children(@Param("id") String id);

    List<Category> findByLevel(int level);

    @Query("select COUNT(c) from Category c where parentId = :id")
    int childrenCount(@Param("id") String id);
}
